package com.xindz.cn.mvptest.components.product.view;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.xindz.cn.mvptest.R;
import com.xindz.cn.mvptest.components.product.data.ProductBean;
import com.xindz.cn.mvptest.shared.core.glide.GlideApp;
import com.xindz.cn.mvptest.shared.core.image.ImageLoader;

import java.util.List;

/**
 * @name MvpTest
 * @class name：com.xindz.cn.mvptest.components.product.view
 * @describe describe
 * @anthor XINDZ
 * @time 2017/10/31 14:36
 * @change
 * @chang time
 * @class describe
 */
public class ProductShowAdapter extends RecyclerView.Adapter<ProductShowAdapter.ViewHolde> {
    private Context mContext;
    private List<ProductBean> mList;

    public ProductShowAdapter(Context mContext, List<ProductBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    public List<ProductBean> getmList() {
        return mList;
    }

    public void setmList(List<ProductBean> mList) {
        this.mList.clear();
        this.mList = mList;
        notifyDataSetChanged();
    }
    @Override
    public ViewHolde onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolde(LayoutInflater.from(mContext).inflate(R.layout.item_product_show, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolde holder, int position) {
        ProductBean productBean = mList.get(position);

        ImageLoader.getInstance(GlideApp.with(mContext)).defaultLoad(productBean.getImage()).into(holder.iv);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("   标题: " + productBean.getTitle());
        stringBuffer.append("   描述: " + productBean.getDescription());
        stringBuffer.append("\n    测试:" + productBean.getXindz());
        stringBuffer.append("   价格" + productBean.getPrice());
        holder.tv.setText(stringBuffer);

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class ViewHolde extends RecyclerView.ViewHolder {
        private ImageView iv;
        private TextView tv;

        public ViewHolde(View itemView) {
            super(itemView);
            iv = itemView.findViewById(R.id.iv_item_product_show);
            tv = itemView.findViewById(R.id.tv_item_produc_show);
        }
    }
}
